<template>
  <div id="change_phone_view2">

    <header class="mui-bar mui-bar-nav">
      <a class=" mui-icon  mui-pull-left  arr_left" @tap="open_change_phone_view2(false)">
      </a>
      <h1 class="mui-title">绑定新手机号</h1>

    </header>
    <div class="my_content mui-content">
      <div class="mu_login-all" id="my_login">
        <ul class="my_login">
          <li class="my_login_li">
            <span>手机号</span>
            <input type="text"  v-model="phone_num" placeholder="请输入新的手机号"/>
          </li>
          <li class="my_login_li">
            <span>验证码</span>
            <input type="text"  v-model="code_msg" placeholder="请输入验证码"  />
            <input class="login-num-btn" @tap="get_code_msg" id="get_msg_btn2" name="color" type="button" value="获取验证码"/>

          </li>
        </ul>
        <div class="my_butn" @tap="next_step">
          <button>确认绑定</button>
        </div>
      </div>
    </div>


  </div>

</template>

<script>
  import phone_msg_ajax from '../../ajax/phone_msg_ajax'
import axios from '../../ajax/ajax'
  export default {
    name: "change_phone2",
    data(){
      return{
        code_msg:'',
        code_server:'',
        phone_num:''
      }
    },
    methods:{

      get_code_msg(){
        let el = document.getElementById("get_msg_btn2");
        let phone  = this.phone_num;
        if(!phone){
          mui.toast("请输入手机号")
          return
        }
        phone_msg_ajax.get_code_msg(el,phone,res=>{
          console.log("获取短信验证码成功-->"+res)
          this.code_server =res;
        })
      },
      next_step(){
        if(!this.code_msg){
          mui.toast("请填写验证码")
        }else {
          if(this.code_msg == this.code_server){

            axios.post(
              "api/User/changephone",
              "phone="+this.phone_num+
              "&uid="+this.$store.state.account.user_info.uid
            ).then(res=>{
              console.log("绑定新手机号")
              console.log(res)
              if(res.code==1){
                mui.toast("更换成功")
                // 自动退出登录
                window.localStorage.clear();
                this.$store.commit("up_data_user","")
                this.$store.commit("up_data_community",null)
                // 关闭更换手机号页面
                this.open_change_phone_view(false);
                this.open_change_phone_view2(false)
              }else {
                mui.toast(res.msg)
              }
            }).catch(err=>{
              console.log(err);

            })

          }else {
            mui.toast("验证码错误")
          }

        }
      },
      open_change_phone_view2(tf){
        this.$store.commit("open_change_phone_view2",tf)
      },
      open_change_phone_view(tf){
        this.$store.commit("open_change_phone_view",tf)
      }

    },
    components:{

    }
  }
</script>

<style scoped lang="less">
  html,
  body {
    background-color: #f6f6f6;
    min-height: 100vh;
    font-size: 0.373rem/0.625;
  }
  #change_phone_view2{
    position: fixed;
    width: 100%;
    height:100%;
    top: 0;
    left: 0;
    z-index: 10002;
    background-color: #fff;
  }
  ul,
  ol {
    list-style: none;
  }

  body input[type='text'],
  ul,
  li {
    padding: 0;
    margin: 0;
  }

  .clear {
    clear: both;
    height: 0;
    font-size: 0;
    line-height: 0;
    visibility: hidden;
    overflow: hidden;
  }
  /*顶部*/

  .my_login_li {
    background: #fff;
    padding: 0 0.373rem/0.625;
    display: flex;
    line-height: 1.333rem/0.625;
    border-bottom: 1px solid #e2e2e2;
    justify-content: center;
    align-items: center;
  }

  .my_login_li span {
    padding-left: 0.373rem/0.625;
    width:7.8rem;
    text-align: left;
  }

  .my_login_li input {
    border: 0;
    line-height: 1.333rem/0.625;
    height: 1.333rem/0.625;
    color: #888888;
  }

  .my_login_li .login-num-btn {
    width: 2.893rem/0.625;
    border: 1px #888888 solid;
    height: 0.786rem/0.625;
    line-height: 0.786rem/0.625;
    padding: 0 0.2rem/0.625;
  }

  .my_content {
    background: #f6f6f6;
  }

  .my_login {
    padding-top: 0.253rem/0.625;
  }

  .my_content button {
    background: url(../../assets/images/my_buttom.png) no-repeat;
    color: #FFFFFF;
    line-height: 1.266rem/0.625;
    height: 1.266rem/0.625;
    width: 100%;
    padding: 0;
    box-sizing: border-box;
    background-size: 100% 100%;
    border: 0;
  }

  .my_butn {
    margin: 1.093rem/0.625 0.373rem/0.625;
  }

  .my_login_li .classcolor {
    background: #000;
    width: 2.893rem/0.625;
    border: 1px #888888 solid;
    height: 0.786rem/0.625;
    line-height: 0.786rem/0.625;
    padding: 0 0.2rem/0.625;
  }

  .my_login_li input[type='text'] {
    font-size: 0.373rem/0.625;
  }
  #phone {
    color: #000000 !important;
  }
</style>
